﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ZBJF.Warranty.Model.ViewModel.BaseQueryModel
{
    [Serializable]
    public class OrderString2ModelFieldArr
    {
        public static List<OrderModelField> ConvertToModelField(string orderString)
        {
            if (string.IsNullOrEmpty(orderString))
            {
                return null;
            }
            //ApplyTime desc,ApplyName asc
            var orderByArr = orderString.Split(',');
            var list = new List<OrderModelField>();
            foreach (var item in orderByArr)
            {
                var arr = item.Trim(' ').Split(' ');
                OrderModelField entity;
                if (arr.Length > 1)
                {
                    entity = new OrderModelField
                    {
                        PropertyName = arr[0],
                        IsDESC = arr[1].Trim().ToLower() != "asc"
                    };
                }
                else
                {
                    if (string.IsNullOrEmpty(arr[0].Trim())) continue;
                    entity = new OrderModelField
                    {
                        PropertyName = arr[0],
                        IsDESC = false
                    };
                }
                list.Add(entity);
            }
            return list;
        }
    }
}
